package com.zzc.fwzpxt.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.zzc.fwzpxt.entity.Product;
import com.zzc.fwzpxt.entity.ProductVo;
import com.zzc.fwzpxt.mapper.ProductMapper;
import com.zzc.fwzpxt.service.IProductService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 产品 product 服务实现类
 * </p>
 *
 * @author XiaoBingBy
 * @since 2017-09-28
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Page<ProductVo> selectMyPage(Page<ProductVo> page, EntityWrapper<ProductVo> entityWrapper) {
        if (null != entityWrapper) {
            entityWrapper.orderBy(page.getOrderByField(), page.isAsc());
        }
        page.setRecords(productMapper.selectMyPage(page, entityWrapper));
        return page;
    }

    @Override
    public List<Product> findRandProduct4() {
        return productMapper.findRandProduct4();
    }

    @Override
    public ProductVo findById(Integer id) {
        return productMapper.findById(id);
    }
}
